using System;
using miPics.Common;


public partial class _Administration_CreateGallery : miPics.BasePage.BaseAdministrationGallery
{
	protected void Page_Load(object sender, EventArgs e)
	{
		// set menu administration task
		Master.SetMenuAdministrationTask("Create new gallery");

		if (!this.IsPostBack)
		{
			// default the new gallery date to the current date and enabled
			_GalleryDate.Value = this.GetNewGalleryDate;
			_GalleryEnabled.Checked = true;
		}
	}

	protected void CreateGallery(object sender, EventArgs e)
	{
		// commit details to a new gallery record

		// validate form details
		string GalleryName = ToolKit.TrimToLength(_GalleryName.Value, 100);
		string GalleryDescription = ToolKit.TrimToLength(_GalleryDescription.Value, 1000);

		if (GalleryName == "")
			_FormErrorList.AddError("Please enter a name for the gallery");

		this.ValidateGalleryDate(_GalleryDate.Value);

		if (GalleryDescription == "")
			_FormErrorList.AddError("Please enter a description for the gallery");

		if (!_FormErrorList.IsError)
		{
			miPicsDataAccessTableAdapters.GalleryItemTableAdapter GalleryItem = new miPicsDataAccessTableAdapters.GalleryItemTableAdapter();

			short NewGalleryID =
				(short)GalleryItem.CreateItem(
					this.ParsedGalleryDate,
					GalleryName,
					_GalleryEnabled.Checked,
					GalleryDescription);

			// redirect back to home
			Response.Redirect("~/");
		}
	}

	protected void CancelCreate(object sender, EventArgs e)
	{
		// redirect back to home
		Response.Redirect("~/");
	}

	protected void SetCurrentDate(object sender, EventArgs e)
	{
		_GalleryDate.Value = this.GetNewGalleryDate;
	}

	protected override string GalleryDateError
	{
		set { _FormErrorList.AddError(value); }
	}
}